package com.rabbitmq.死信队列.超过最大长度;

import com.rabbitmq.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @Auther: liyanhao
 * @Description: 死信队列的消费者
 * @Date: 2022/5/11 23:01
 * @Version: v1.0
 */
public class Consumer02 {
    //死信交换机
    private static final String DEAD_EXCHANGE = "dead_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(DEAD_EXCHANGE, BuiltinExchangeType.DIRECT);
        String deadQueue = "dead_queue";
        channel.queueDeclare(deadQueue, false, false, false, null);
        channel.queueBind(deadQueue, DEAD_EXCHANGE, "lisi");
        System.out.println("等待接收死信队列消息....");
        DeliverCallback deliverCallback = ((consumerTag, message) -> {
            new String(message.getBody(), "UTF-8");
            System.out.println("Consumer02 接收死信队列的消息" + message);
        });
        channel.basicConsume(deadQueue, true, deliverCallback, consumerTag -> {
        });
    }
}
